home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / AIFF_DSP_v15 folder / AIFF_DSP / ringmod.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-31  |  1.5 KB  |  66 lines  |  [TEXT/KAHL]

  1. /*
  2. FILE:     ringmod.c
  3. PROJECT:  Ford grant DSP
  4. AUTHOR:   Ben Denckla
  5. COMMENTS: fixed-frequency sinusoidal-carrier ring modulation
  6. LINKAGE:  needs sintab.c
  7. */
  8.  
  9. #include "aiff.h"
  10. #include "sintab.h"
  11.  
  12. #include <stdlib.h>
  13.  
  14. int take_input = 1, make_output = 1;
  15.  
  16. static short *sintab4, harm;
  17.  
  18. void init_process( void ) {
  19.     if ( (ba.com.wdsi < 9) || (ba.com.wdsi > 16) )
  20.         err( "Cannot process a file with this word size" );
  21.     if ( ba.com.chan != 1 )
  22.         err( "Cannot process a multi-channel file" );
  23.  
  24.     get_sintab();            // get a 1st-quadrant sine wave table
  25.     sintab4 = gen_sintab4(); // generate a 4-quadrant sine wave table
  26.     harm = getusrharm();     // get harmonic desired from user
  27. }
  28.  
  29. void term_process( void ) {
  30.     free ( sintab4 );
  31. }
  32.  
  33. void process_samdat( long buflen ) {
  34.     register long  t;
  35.     register short *td, *endd, *tsintab4, tharm, tphase, ttabmask;
  36.     static short phase = 0;
  37.  
  38.     td       = d;
  39.     tsintab4 = sintab4;
  40.     tharm    = harm;
  41.     tphase   = phase;
  42.     ttabmask = TABMASK;
  43.     endd     = &td[buflen];
  44.  
  45.     do {
  46.         t = (long) *td * tsintab4[ tphase &= ttabmask ];
  47.         asm { swap t }; // 1
  48.         *td++ = t;
  49.         tphase += tharm; // 2
  50.     } while ( td < endd );
  51.     
  52.     phase = tphase;
  53. }
  54. /*
  55. 1. To profile, use t >>= 16 instead.  (Can't profile a function w/ asm.)
  56.  
  57. loop:
  58. 00000026        AND.W     ttabmask,tphase
  59. 00000028        MOVE.W    $00(tsintab4,tphase.W*2),D7
  60. 0000002C        MULS.W    *td,D7
  61. 0000002E        SWAP      D7
  62. 00000030        MOVE.W    D7,*td++
  63. 00000032        ADD.W     harm,tphase
  64. 00000034        CMPA.L    td,end
  65. 00000036        BHI.S     loop
  66. */